package com.fanqwz.kotlinmvvm.data.web.entity

import com.fanqwz.kotlinmvvm.common.util.rxjava.gson.GsonNullDeserializer
import com.fanqwz.kotlinmvvm.domain.`object`.User
import com.google.gson.annotations.JsonAdapter
import com.google.gson.annotations.SerializedName
import org.parceler.Parcel

/**
 * Created by fanqwz on 2017/10/18.
 */

/** ！！！注意：使用可空参数的构造函数，否则gson解析会找不到默认无参构造器*/
@JsonAdapter(GsonNullDeserializer::class)
@Parcel(Parcel.Serialization.BEAN)
data class UserEntity(
        @SerializedName("user_name")
        var name: String? = null,
        @SerializedName("user_pwd")
        var passwd: String? = null,
        @SerializedName("user_no")
        val code: String? = null
)

fun UserEntity.toUser(): User {
    return User(0, name ?: "无名", password = "")
}

data class LoginRequestBody(@SerializedName("userNo") val name: String,
                            @SerializedName("userPwd") val password: String)
